/*
 * VotingActions.h
 *
 *  Created on: Oct 12, 2011
 *      Author: kimi
 */

#ifndef VOTINGACTIONS_H_
#define VOTINGACTIONS_H_
#include "Configuration/Properties.h"
#include "DataStructures/Hash/ExtensibleHash.h"
#include "DataStructures/BTree/BTree.h"
#include "DataStructures/BlocksFile.h"
#include "DataStructures/Block.h"
#include "Parser/DistritoParser.h"
#include "Model/Distrito.h"
#include "Parser/VotantesParser.h"
#include "Model/Votante.h"
#include "Parser/EleccionParser.h"
#include "Model/Eleccion.h"
#include "Parser/CargoParser.h"
#include "Model/Cargo.h"
#include "Parser/ListaParser.h"
#include "Model/Lista.h"
#include "Parser/CandidatoParser.h"
#include "Model/Candidato.h"
#include "Model/Voto.h"
#include "Parser/VotoAutomaticoParser.h"
#include "Parser/ListaParser.h"
#include "Model/Lista.h"
#include "Parser/CandidatoParser.h"
#include "Model/Candidato.h"

#include "Administrator/AdminManager.h"

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <unistd.h>

#include "VotingHelper.h"

#include "CLI/CLI.h"

#include "DataStructures/Voting/CountingMgr.h"
#include "Report/Reports.h"

#include "Crypto/RSA.h"
#include "AntiCrypto/RSABreaker.h"

using namespace std;


class VotingActions {

public:

	unsigned long addDistritos(string distritosFile,unsigned long* distritosAdded, unsigned long* distritosUpdated);
	bool getDistrito(unsigned long distritoId,Distrito ** distrito);
	int doDistritosAction(CLIEntity * entity);

	unsigned long addVotantes(string votantesFile,unsigned long* votantesAdded, unsigned long* votantesUpdated);
	bool getVotante(unsigned long votanteId,Votante ** votante);
	int doVotantesAction(CLIEntity * entity);

	unsigned long addCargos(string cargosFile,unsigned long* cargosAdded, unsigned long* cargosUpdated);
	bool getCargo(unsigned long cargoId,Cargo ** cargo);
	int doCargosAction(CLIEntity * entity);

	unsigned long addElecciones(string eleccionesFile,unsigned long* eleccionesAdded, unsigned long* eleccionesUpdated); 
	bool getEleccion(unsigned long eleccionId,Eleccion ** eleccion);
	int doEleccionesAction(CLIEntity * entity);

	unsigned long addListas(string listaFile,unsigned long* listasAdded, unsigned long* listasUpdated);
	bool getLista(unsigned long listasId,Lista ** listas);
	int doListasAction(CLIEntity * entity);

	unsigned long addCandidatos(string candidatosFile,unsigned long* candidatosAdded, unsigned long* candidatosUpdated);
	bool getCandidato(unsigned long candidatoId,Candidato ** candidato);
	int doCandidatosAction(CLIEntity * entity);

	vector<Lista> convertListIDsIntoList(vector<unsigned long> ids);
	bool votar(CLIEntity *entity);

	VotingActions(string filePath);
	virtual ~VotingActions();

	int doAction(int argc, char ** argv);

	bool ingresarVotosDesdeArchivo(string filePath);

	bool encriptarArchivoDeAdministradores();
	bool romperRSAConClavePublica();

	bool checkSystemIntegrity();
private:
	Properties* props;
	VotingHelper* votingHelper;

	string getPlainFileFromRSACrytro(string encryptedFile);
	bool getRSACrytroFromPlainFile(string plainFile,string encryptedFile);
};

#endif /* VOTINGACTIONS_H_ */
